//
//  HTStatus.swift
//  WeiBoDemo
//
//  Created by 郝涛 on 16/4/21.
//  Copyright © 2016年 郝涛. All rights reserved.
//

import UIKit

class HTStatus: NSObject {

    
    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?

    //用户模型
    var user:HTUser?
    
    // // 转发微博的(如果没有转发微博 服务器会返回一个nil)
    var retweeted_status:HTStatus?
   //配图数组
    var pic_urls:[HTPictureInfo]?

   
    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0

    
    //KVC
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    //重写setValuesForKeysWithDictionary
    override func setValue(value: AnyObject?, forKey key: String) {
        // 判断如果是我们自己定义的CZUser 模型我们需要自己 字典转模型 然后赋值给我们的user
        if key == "user"{
            if let v = value as? [String:AnyObject]{
                let u = HTUser(dict: v)
                user = u
            }
        }else if key == "retweeted_status"{
            // 判断是转发微博
            if let v = value as? [String:AnyObject]{
                let s = HTStatus(dict: v)
                retweeted_status = s
            }
            //配图数据
        }else if key == "pic_urls"{
            // 判断是转发微博
            if let array  = value as? [[String:AnyObject]]{
                
                var tmpArray :[HTPictureInfo] = [HTPictureInfo]()
                
                //遍历数组转模型
                for dict in array {
                    
                    let pictureInfo = HTPictureInfo(dict: dict)
                    
                    //添加到临时数组
                    tmpArray.append(pictureInfo)
                }
                pic_urls = tmpArray
            }
        }else{
            super.setValue(value, forKey: key)
        }
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
